<template>
  <div class="update-gender">
    <van-picker
      title="标题"
      show-toolbar
      :columns="columns"
      :default-index="defaultIndex"
      @confirm="onConfirm"
      @cancel="$emit('close')"
      @change="onChange"
    />
  </div>
</template>

<script>
  import { UpdateUserProfile } from '@/api/user'

  export default {
   name: 'UpdateGender',
	 components:{},
	 props:{
     value:{
       type:Number,
       required:true
     }
   },
   data () {
     return {
       columns: ['男', '女'],
       defaultIndex:this.value
     }
   },
	 computed: {},
	 watch: {},
	 created () {},
	 mounted() {},
   methods:{
     async onConfirm () {
       this.$toast.loading({
         message:'保存中',
         forbidclick:true //禁止背景点击
       })

       //请求提交更新用户性别
       await UpdateUserProfile({
         gender:this.defaultIndex
       })

       //更新成功 -> 修改父组件的name -> 关闭弹出层
       //发布input事件，更新父组件v-model绑定的数据
       this.$emit('input',this.defaultIndex)
       //this.$emit('update-name',this.localName)
       this.$emit('close')

       this.$toast.success('保存成功')
     },

     onChange(picker, value, index) {
       this.defaultIndex = index
     }
   }
  }
</script>

<style scoped lang="less">
</style>
